package com.itheima.springboot2enable;

import com.itheima.config.EneableUser;
import com.itheima.config.MyImportBeanDefinitionRegistrar;
import com.itheima.config.MyImportSelector;
import com.itheima.config.UserConfig;
import com.itheima.domain.Student;
import com.itheima.domain.User;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import java.util.Map;

/**
 * @ComponentScan 扫描范围：当前引导类所在包及其子包
 *
 * com.itheima.config
 *
 *  //1.使用@ComponentScan扫描com.itheima.config包
 * //2.可以使用@Import注解，加载类。   这些类都会被Spring创建，并放入IOC容器
 * //3.可以对Import注解进行封装。
 *
 */

/**
 * Import4中用法：
 *  1. 导入Bean
 *  2. 导入配置类
 *  3. 导入ImportSelector的实现类。
 *  4. 导入ImportBeanDefinitionRegistrar实现类
 */

@SpringBootApplication
//@ComponentScan("com.itheima.config")
//@Import(UserConfig.class)
//@EneableUser


//@Import(User.class)
//@Import(UserConfig.class)
//@Import(MyImportSelector.class)
@Import(MyImportBeanDefinitionRegistrar.class)
public class Springboot2EnableApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Springboot2EnableApplication.class, args);

        /*//获取Bean
        Object user = context.getBean("user");
        System.out.println(user);*/

        User bean = context.getBean(User.class);
        System.out.println(bean);

        /*Map<String, User> type = context.getBeansOfType(User.class);
        System.out.println(type);*/
        //{com.itheima.domain.User=com.itheima.domain.User@37ff4054}

        Student student = context.getBean(Student.class);
        System.out.println(student);
    }

}
